class Solution {
public:
    int thirdMax(vector<int>& nums) {
        int count = 0;
        long long  Max = LONG_MAX;
        sort(nums.begin(), nums.end());
        for (int i = nums.size() - 1; i >= 0; i--)
        {
            if (nums[i] < Max)
            {
                Max = nums[i];
                count++;
            }
            if (count == 3)
                return Max;
        }
        return nums[nums.size() - 1];
    }
};